<admintpl file="header" />
<style type="text/css">
    .radio {
        margin-top: 5px;
        margin-left: 15px;
        float: left;
    }
</style>
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">

            <li><a href="{:U('Advertising/index')}">广告管理</a></li>
            <li class="active"><a href="{:U('Advertising/add')}">添加广告</a></li>
		</ul>
		<form action="{:U('Advertising/add_post')}" method="post" class="form-horizontal js-ajax-form" enctype="multipart/form-data">
			<div class="row-fluid">
				<div class="span9">
					<table class="table table-bordered">
						<tr>
							<th>名称</th>
							<td>
								<input type="text" name="aname"  value="" placeholder="广告名"/>
							</td>
						</tr>
						<tr>
							<th>类型</th>
							<td>
			                <foreach name="adtype" item="vo">
                                <if condition="$vo['id']" >
				                    <label class="radio">
				                        <input type="radio" name="atype" value="{$vo.id}">
				                        <span>{$vo.name}</span>
				                    </label>
			                    </if>
			                </foreach>
							</td>
						</tr>
						<tr>
							<th>开始日期</th>
							<td><input type="text" name="start_at" value="{:date('Y-m-d H:i',time())}" class="js-datetime"></td>
						</tr>
						<tr>
							<th>结束日期</th>
							<td><input type="text" name="end_at" value="{:date('Y-m-d H:i',strtotime('+7 day'))}" class="js-datetime"></td>
						</tr>
						<tr>
							<th>广告连接</th>
							<td>
								<input type="text" name="adurl" placeholder="请填写连接"/>请填写完整连接。如：http://cn.bing.com/
							</td>
						</tr>
						<tr>
							<th>备注</th>
							<td>
								<input type="text" name="description"  placeholder="广告备注"/>
							</td>
						</tr>
					</table>
				</div>
				<div class="span3">
					<table class="table table-bordered">
						<tr>
							<td><b>图片</b></td>
						</tr>
						<tr>
							<td>
								<input type="file" readonly="readonly" name="update_img" id="adfile" accept="image/*"/>
								<input type="button" class="btn btn-small" onclick="$('#adfile').attr('value','');$('#aimg').attr('src','');return false;" value="取消图片">
							</td>
						</tr>
						<tr>
							<td><img src="" id="aimg"></td>
						</tr>
					</table>
				</div>
			</div>
			<div class="form-actions">
				<button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
				<a class="btn" href="{:U('Advertising/index')}">返回</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript">
	$("#adfile").change(function(){
		var objUrl = getObjectURL(this.files[0]) ;
		console.log("objUrl = "+objUrl) ;
		if (objUrl) {
			$("#aimg").attr("src", objUrl) ;
		}
	}) ;
	function getObjectURL(file) {
		var url = null ;
		if (window.createObjectURL!=undefined) { // basic
			url = window.createObjectURL(file) ;
		} else if (window.URL!=undefined) { // mozilla(firefox)
			url = window.URL.createObjectURL(file) ;
		} else if (window.webkitURL!=undefined) { // webkit or chrome
			url = window.webkitURL.createObjectURL(file) ;
		}
		return url ;
	}
	</script>
</body>
</html>